package com.dycloud.project.service;

import com.dycloud.project.utils.SecurityUtils;
import com.dycloud.project.vo.AnalyzeDataVO;
import com.dycloud.project.vo.PushTrendItemVo;
import com.dycloud.project.vo.PushTrendVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : renhang
 * @description IndexService
 * @date : 2025-07-03 23:38
 **/
@Service
public class IndexService {

    @Resource
    private IIndustryTrendsService industryTrendsService;

    @Resource
    private IMeetingsService meetingsService;

    @Resource
    private ICourseService courseService;


    public AnalyzeDataVO analyze() {
        Long userId = SecurityUtils.getUserId();
        if (SecurityUtils.isAdmin(userId)) {
            int industryCount = industryTrendsService.selectCount(null);
            int meetingCount = meetingsService.selectCount(null);
            int courseCount = courseService.selectCount(null);
            return AnalyzeDataVO.builder()
                    .industryCount(industryCount)
                    .meetingCount(meetingCount)
                    .courseCount(courseCount)
                    .build();
        }
        int industryCount = industryTrendsService.selectCount(userId);
        int meetingCount = meetingsService.selectCount(userId);
        int courseCount = courseService.selectCount(userId);
        return AnalyzeDataVO.builder()
                .industryCount(industryCount)
                .meetingCount(meetingCount)
                .courseCount(courseCount)
                .build();
    }

    public PushTrendVo publishTrend() {
        Long userId = SecurityUtils.getUserId();
        if (SecurityUtils.isAdmin(userId)) {
            List<PushTrendItemVo> industryTrends = industryTrendsService.selectPushTrend(null);
            List<PushTrendItemVo> courses = courseService.selectPushTrend(null);
            List<PushTrendItemVo> meetings = meetingsService.selectPushTrend(null);
            return PushTrendVo.builder()
                    .industryTrendList(industryTrends)
                    .courseList(courses)
                    .meetingList(meetings)
                    .build();
        }

        List<PushTrendItemVo> industryTrends = industryTrendsService.selectPushTrend(userId);
        List<PushTrendItemVo> courses = courseService.selectPushTrend(userId);
        List<PushTrendItemVo> meetings = meetingsService.selectPushTrend(userId);
        return PushTrendVo.builder()
                .industryTrendList(industryTrends)
                .courseList(courses)
                .meetingList(meetings)
                .build();
    }
}
